<?php

	class Question extends Question_model {

            protected $__relation = array(
			array('table' => 'question_type', 'foreign_key' => 'question_type_id')
		);
            
		function __construct() {
			parent::__construct();
		}
                
                function delete() {
                    $answer = new Answer();
                    $answer->query("DELETE FROM answer WHERE question_id = $this->id");
                    parent::delete();
                }


                function isDeleteAble($id) {
                    /*
                    $answer = new Answer();
                    $answer->addSelect();
                    $answer->addSelect("answer.id");
                    $answer->addWhere("answer.question_id = $id");
                    $answer->find();
                    return $answer->countRows() > 0 ? false : true;
                    */
                    return true;
                }
                
                function isAnswerDeleteAble($answer_id) {
                    //return Answer::isDeleteAble($answer_id);
                    return true;
                }
                
                function validateInput() {
                    if (!$this->title || trim($this->title) == '')
                        MessageHandler::add ("Missing question title");
                    
                    if (!$this->question_type_id)
                        MessageHandler::add ("Missing question type ID");
                    
                    if ($this->id && (!$this->image || trim($this->image) == ''))
                        MessageHandler::add ("Missing picture");
                    
                    return MessageHandler::countError() > 0 ? false : true;
                }
	}
